home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_542 / pp / asmsup.c < prev    next >
Text File  |  1992-05-06  |  3KB  |  88 lines

  1. /* asmsup.c
  2. **
  3. ** This is the assembler support code used by PP. It contains code for
  4. ** patching the DOS library. Context sensitivity has been added since
  5. ** v1.1 - these routines now act differently when running under DOS2.0
  6. **
  7. ** Freeware 1991, Copyright (C) 1991 by Michael Berg
  8. */
  9.  
  10. #asm
  11. DOSLibPatch    MACRO
  12.         public    _Real\1
  13.         public    _New\1
  14.         public    _Make\1
  15.         public    _Rest\1
  16.         public    _LVO\1
  17.         public    \2
  18.  
  19. _Make\1        movem.l    a6/d0-d2,-(sp)        ;save registers
  20.         move.l    \2,a6            ;store DOSBase in a6
  21.         movem.w    _LVO\1(a6),d0-d2    ;get the 3-word original seq.
  22.         movem.w    d0-d2,Orig\1        ;save these words
  23.         cmp.w    #$4ef9,d0        ;determine state of DOS vect.
  24.         bne.s    1$            ;original 1.2/1.3 DOS code
  25.  
  26.         lea    _Real\1,a0        ;takes care of 2.0/already
  27.         move.l    _LVO\1+2(a6),d0        ;patched code. Get the JMP
  28.         move.l    d0,4(a0)        ;target and create our own
  29.         move.w    #$4e71,(a0)        ;little code stub. 4e71='NOP'
  30.         lea    _New\1,a0        ;(we will not be needing the
  31.         move.l    a0,d0            ;moveq)
  32.         move.l    d0,_LVO\1+2(a6)
  33.         bra.s    2$
  34.  
  35. 1$        lea    _LVO\1(a6),a6
  36.         moveq    #0,d0
  37.         lea    _Real\1,a0
  38.         move.w    (a6),(a0)    ;fetch the 'moveq #?,d0' opcode
  39.         move.w    4(a6),d0    ;fetch the 'bra' offset
  40.         add.l    a6,d0        ;add to find branch target
  41.         addq.l    #4,d0        ;pc relative offset compensation
  42.         move.l    d0,4(a0)    ;we need this so we can jump directly
  43.         move.w    #$4ef9,(a6)    ;initiate new sequence: jmp $abs_addrs
  44.         move.l    #_New\1,2(a6)    ;jump to our new function, of corz!
  45. 2$        movem.l    (sp)+,a6/d0-d2    ;restore regs
  46.         rts
  47.  
  48. _Real\1        moveq    #0,d0        ;moveq value will be ajusted
  49.         jmp    $fffffe        ;the JMP address will be fixed
  50.  
  51.         dseg
  52. Orig\1        dc.w    0,0,0
  53.         cseg
  54.  
  55. _Rest\1        move.w    d2,-(sp)
  56.         move.l    \2,a0
  57.         movem.w    Orig\1,d0-d2
  58.         movem.w    d0-d2,_LVO\1(a0)
  59.         move.w    (sp)+,d2
  60.         rts
  61.         ENDM
  62.  
  63. ;DOSLibPatch is a macro which defines three functions. For Open(), they are:
  64. ;
  65. ;MakeOpen    - Patch the DOS library Open() vector
  66. ;RestOpen    - Restore the DOS library to it's original state
  67. ;RealOpen    - This calls the original DOS function
  68. ;
  69. ;Furthermore, you yourself have to create a function called (in this case)
  70. ;NewOpen, with a parameter specification like Open(). Future calls to Open
  71. ;will be redirected to NewOpen. NewOpen has access to the original DOS code
  72. ;through the function RealOpen. RealOpen should also be defined like Open.
  73. ;More details follow. For now, you need to know that DOSLibPatch works only
  74. ;with the DOS library, which differes in format from other libraries. Also
  75. ;note that these functions are sensitive to their environment. Versions 1.2
  76. ;and 1.3 of the OS has this weird looking DOS library, where 2.0 has had its
  77. ;DOS library normalized to conform to the appearance of the other libraries.
  78. ;The global variable 'os20' controls the flow of these functions. If running
  79. ;under 2.0, this variable MUST be set to a non-zero value.
  80.  
  81.         XREF    _os20
  82.  
  83.         DOSLibPatch Open,_DOSBase
  84.         DOSLibPatch Close,_DOSBase
  85.         DOSLibPatch Examine,_DOSBase
  86.         DOSLibPatch Write,_DOSBase
  87. #endasm
  88.